package com.atcumt.bytedance;


import java.util.Arrays;
import java.util.Scanner;

/**
 * 合并编号
 * 第一行N,代表共几个编号, 后续每行代表一个编号, 输出排序好的合并编号
 * 4
 * 0000-0000-10-98
 * 0000-0000-10-99
 * 0000-0000-11-00
 * 0000-0000-11-01
 * <p>
 * 0000-0000-10-98 to 11-01
 */
public class Main03 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        int n = Integer.parseInt(s);
        if (n == 0) {
            return;
        }

        String[] ss = new String[n];
        for (int i = 0; i < n; i++) {
            ss[i] = scanner.nextLine();
        }
        Arrays.sort(ss);

        int start = 0;
        String last = ss[0];
        for (int i = 1; i < n; i++) {
            if (compare(last, ss[i])) {
                last = ss[i];
            } else {
                if (start == i - 1) {
                    System.out.println(ss[i - 1]);
                } else {
                    int prefix = getPre(ss[start], ss[i - 1]);
                    System.out.println(ss[start] + " to " + ss[i - 1].substring(prefix));
                }
                start = i;
                last = ss[i]; // 清空
            }
        }
        // i = n 特殊处理
        int i = n;
        if (start == i - 1) {
            System.out.println(ss[i - 1]);
        } else {
            int prefix = getPre(ss[start], ss[i - 1]);
            System.out.println(ss[start] + " to " + ss[i - 1].substring(prefix));
        }
    }

    private static int getPre(String s1, String s2) {
        int idx = 0;
        for (int i = 0; i < s1.length(); i++) {
            if (s1.charAt(i) == '-') {
                idx = i;
            } else if (s1.charAt(i) != s2.charAt(i)) {
                return idx + 1;
            }
        }
        return s1.length();
    }

    /**
     * 比较两字符串相差是否为 1
     */
    private static boolean compare(String s1, String s2) {
        int flag = 0; // 进位标志
        int sub = 0; // 截断字符串

        for (int i = s1.length() - 1; i >= 0; i--) {
            if (s1.charAt(i) == '-') {
                continue;
            }
            int cur = s2.charAt(i) - s1.charAt(i) - flag;
            if (cur < 0) {
                // 10-98  10-99  11-00
                cur += 10;
                flag = 1;
            } else {
                flag = 0;
            }
            sub += cur;
        }
        return sub == 1;
    }
}
